package h_10_25;

/**
 * 1493. 删掉一个元素以后全为 1 的最长子数组
 * https://leetcode.cn/problems/longest-subarray-of-1s-after-deleting-one-element/description/
 */
public class Main3 {
    public int longestSubarray(int[] nums) {
        int n = nums.length;
        int[] arr = new int[2];
        int left = 0;
        int right = 0;
        int ret = 0;
        while(right < n) {
            // 入
            int x = nums[right];
            arr[x]++;

            // 出
            while(arr[0] > 1) {
                int out = nums[left];
                arr[out]--;
                left++;
            }

            // 更新
            ret = Math.max(ret,right - left + 1);
            right++;
        }
        return ret - 1;
    }
}
